package com.weishaoying.rws.web;

import com.weishaoying.rws.entity.User;
import com.weishaoying.rws.service.UserServiceRws;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 读写分离使用
 *
 * @author WeiShaoying
 * @date 2018/5/5
 */
//@RestController
//@RequestMapping(value = "/rws")
public class RwsController {

    @Autowired
    private UserServiceRws userServiceRws;

    @GetMapping(value = "/query/{id}")
    public User query(@PathVariable Long id) {
        System.out.println("id = [" + id + "]");
        return userServiceRws.queryUser(id);
    }

    @GetMapping(value = "/queryAll")
    public List<User> queryAllUsers() {
        return userServiceRws.queryAll();
    }

    @PostMapping(value = "/save")
    public String saveUser(@RequestBody User user) {
        userServiceRws.saveUser(user);
        return "OK";
    }

    @PostMapping(value = "/update")
    public String updateUser(@RequestBody User user) {
        userServiceRws.updateUser(user);
        return "OK";
    }

    @GetMapping(value = "/delete/{id}")
    public String deleteUser(@PathVariable Long id) {
        userServiceRws.deleteUser(id);
        return "OK";
    }

}
